//////////////////////////////////////////////////////////////////////////////////////
//
//  Copyright (c) 2014-present, Egret Technology.
//  All rights reserved.
//  Redistribution and use in source and binary forms, with or without
//  modification, are permitted provided that the following conditions are met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//     * Neither the name of the Egret nor the
//       names of its contributors may be used to endorse or promote products
//       derived from this software without specific prior written permission.
//
//  THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
//  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
//  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
//  IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
//  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
//  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
//  OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
//  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
//  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////////////

class Main extends egret.DisplayObjectContainer {

    public constructor() {
        super();
        this.addEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this);
    }

    private onAddToStage(event: egret.Event) {

        egret.lifecycle.addLifecycleListener((context) => {
            // custom lifecycle plugin

            context.onUpdate = () => {

            }
        })

        egret.lifecycle.onPause = () => {
            egret.ticker.pause();
        }

        egret.lifecycle.onResume = () => {
            egret.ticker.resume();
        }

        this.runGame().catch(e => {
            console.log(e);
        })



    }

    private async runGame() {
        await this.loadResource()
        this.createGameScene();
        // const result = await RES.getResAsync("description_json")
        // this.startAnimation(result);
        await platform.login();
        const userInfo = await platform.getUserInfo();
        console.log(userInfo);

    }

    private async loadResource() {
        try {
            const loadingView = new LoadingUI();
            this.stage.addChild(loadingView);
            await RES.loadConfig("resource/default.res.json", "resource/");
            await RES.loadGroup("preload", 0, loadingView);
            this.stage.removeChild(loadingView);
        }
        catch (e) {
            console.error(e);
        }
    }

    private textfield: egret.TextField;

    /**
     * 创建游戏场景
     * Create a game scene
     */
    private createGameScene() {
    //     let yuan1:egret.Shape=new egret.Shape();
    //     yuan1.graphics.lineStyle(5,0xff0000)
    //     yuan1.graphics.beginFill(0x0000ff,1);
    //     yuan1.graphics.drawCircle(-20,-20,100);      
    //     this.addChild(yuan1);

    //     let yuan2:egret.Shape=new egret.Shape();
    //     yuan2.graphics.lineStyle(5,0xff0000)
    //     yuan2.graphics.beginFill(0x0000ff,1);
    //     yuan2.graphics.drawCircle(this.stage.stageWidth+20,-20,100);      
    //     this.addChild(yuan2);

    //     let rect:egret.Shape=new egret.Shape()
    //     rect.graphics.beginFill(0xff0000);
    //     rect.graphics.drawRect(170,100,300,170);
    //     rect.graphics.endFill();
    //     this.addChild(rect)

    //     let t:egret.TextField=new egret.TextField();
    //     this.addChild(t);
    //     t.text="个人介绍"
    //     t.textColor=0xFFFF00
    //     t.size=66;
    //     t.fontFamily="黑体"
    //     t.x=180;
    //     t.y=150;

    //     let rect1:egret.Shape=new egret.Shape()
    //     rect1.graphics.lineStyle(5,0xff0000)       
    //     rect1.graphics.drawRect(30,400,250,250);
    //     rect1.graphics.endFill();
    //     this.addChild(rect1);

    //     let yuan3:egret.Shape=new egret.Shape();
    //     yuan3.graphics.lineStyle(5,0xff0000)        
    //     yuan3.graphics.drawCircle(160,520,100);      
    //     this.addChild(yuan3);

    //     let yuan4:egret.Shape=new egret.Shape();
    //     yuan4.graphics.lineStyle(5,0xff0000)        
    //     yuan4.graphics.drawCircle(110,480,20);      
    //     this.addChild(yuan4);

    //     let yuan5:egret.Shape=new egret.Shape();
    //     yuan5.graphics.lineStyle(5,0xff0000)        
    //     yuan5.graphics.drawCircle(210,480,20);      
    //     this.addChild(yuan5);

    //      let xiaolian:egret.Shape=new egret.Shape();
    //     xiaolian.graphics.lineStyle(5,0xff0000);
    //     xiaolian.graphics.drawArc(160,500,100,Math.PI/3,Math.PI/3*2);
    //     this.addChild(xiaolian);
        
    //     let line:egret.Shape=new egret.Shape();
    //     line.graphics.lineStyle(5,0xff000);
    //     line.graphics.moveTo(300,400);
    //     line.graphics.lineTo(300,650);
    //     this.addChild(line);

    //     let t1:egret.TextField=new egret.TextField();
    //     this.addChild(t1);
    //     t1.text="姓名";
    //     t1.textColor=0xff0000;
    //     t1.size=50;
    //     t1.fontFamily="黑体";
    //     t1.x=400;
    //     t1.y=400;
    //     t1.border=true;
    //     t1.borderColor=0x00ff00;
    //     t1.width=this.stage.stageWidth/3
    //     this.addChild(t1)

    //     let t2:egret.TextField=new egret.TextField();
    //     this.addChild(t2);
    //     t2.text="杨端";
    //     t2.textColor=0xff0000;
    //     t2.size=50;
    //     t2.fontFamily="黑体";
    //     t2.x=400;
    //     t2.y=500;
    //     t2.width=this.stage.stageWidth/3
    //     this.addChild(t2)

    //     let t3:egret.TextField=new egret.TextField();
    //     this.addChild(t3);
    //     t3.text="电话";
    //     t3.textColor=0xff0000;
    //     t3.size=50;
    //     t3.fontFamily="黑体";
    //     t3.x=50;
    //     t3.y=700;
    //     t3.border=true;
    //     t3.borderColor=0x00ff00;
    //     t3.width=this.stage.stageWidth/3
    //     this.addChild(t3)

    //     let t4:egret.TextField=new egret.TextField();
    //     this.addChild(t4);
    //     t4.text="兴趣爱好";
    //     t4.textColor=0xff0000;
    //     t4.size=50;
    //     t4.fontFamily="黑体";
    //     t4.x=50;
    //     t4.y=830;
    //     t4.border=true;
    //     t4.borderColor=0x00ff00;
    //     t4.width=this.stage.stageWidth/3
    //     this.addChild(t4)

    //     let t5:egret.TextField=new egret.TextField();
    //     this.addChild(t5);
    //     t5.text="玩游戏，看小说";
    //     t5.textColor=0xff0000;
    //     t5.size=50;
    //     t5.fontFamily="黑体";
    //     t5.x=100;
    //     t5.y=910;
    //     t5.border=true;
    //     t5.borderColor=0x00ff00;
    //     t5.width=this.stage.stageWidth/2+150;
    //     t5.height=200;
    //     this.addChild(t5)

    //     let t6:egret.TextField=new egret.TextField();
    //     this.addChild(t6);
    //     t6.text="110";
    //     t6.textColor=0xff0000;
    //     t6.size=50;
    //     t6.fontFamily="黑体";
    //     t6.x=400;
    //     t6.y=700;
    //     t6.width=this.stage.stageWidth/2
    //     this.addChild(t6)

    //     let yuanhu:egret.Shape=new egret.Shape();
    //     yuanhu.graphics.lineStyle(5,0xff0000)
    //     yuanhu.graphics.beginFill(0x0000ff,1);
    //     yuanhu.graphics.drawArc(0,0,50,Math.PI,0);
        
    //     yuanhu.x=350;
    //     yuanhu.y=880;
    //     this.addChild(yuanhu);

    //     let yuanhu1:egret.Shape=new egret.Shape();
    //     yuanhu1.graphics.lineStyle(5,0xff0000)
    //     yuanhu1.graphics.beginFill(0x0000ff,1);
    //     yuanhu1.graphics.drawArc(0,0,50,Math.PI,0);      
    //     yuanhu1.x=450;
    //     yuanhu1.y=880;
    //     this.addChild(yuanhu1);

    //     let yuanhu2:egret.Shape=new egret.Shape();
    //     yuanhu2.graphics.lineStyle(5,0xff0000)
    //     yuanhu2.graphics.beginFill(0x0000ff,1);
    //     yuanhu2.graphics.drawArc(0,0,50,Math.PI,0);
        
    //     yuanhu2.x=550;
    //     yuanhu2.y=880;
    //     this.addChild(yuanhu2);
    let wz:egret.TextField=new egret.TextField();
    this.addChild(wz);
    wz.width=600;
    wz.height=700;
    wz.x=100;
    wz.y=500;
    wz.textFlow=<egret.ITextElement[]>[
        {text:"妈妈再也不在担心我在",style:{size:20,textColor:0x000000}},
        {text:'Egret',style:{size:50,textColor:0x0000ff,bold:true}},
        {text:"里说一句话不\n",style:{size:20,textColor:0x000000}},
        {text:"          能包含各种",style:{size:20,textColor:0x000000}},
        {text:"五",style:{size:20,textColor:0xff0000}},
        {text:"彩",style:{size:20,textColor:0x00ff00}},
        {text:"缤",style:{size:20,textColor:0x056fd0}},
        {text:"纷",style:{size:20,textColor:0x0000ff}},
        {text:",\n",style:{size:20,textColor:0x000000}},
        {text:"   大",style:{size:35,textColor:0x000000,bold:true}},
        {text:"小",style:{size:18,textColor:0x000000}},
        {text:"不",style:{size:20,textColor:0x000000}},
        {text:"一.",style:{size:35,textColor:0x000000,}},
        {text:"格",style:{size:20,textColor:0x000000,italic:true}},
        {text:"式",style:{size:20,textColor:0xff0000,}},
        {text:"各",style:{size:20,textColor:0x00ff00,italic:true}},
        {text:"样",style:{size:20,textColor:0x0000ff,}},
        {text:"的文字了！",style:{size:20,textColor:0x000000}},



    ]
    }
}